package com.foreveross.action.weixin;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.foreveross.common.CommonUtil;
import com.foreveross.common.Constants;
import com.foreveross.service.LogService;
import com.foreveross.service.MessageService;
import com.foreveross.util.AuthUtil;
import com.foreveross.vo.Message;
import com.foreveross.vo.common.PageVo;
import com.foreveross.vo.common.ResultVo;
/**
 * 消息通知
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/weixin/MessageController")
public class MessageController {

	private Logger log = Logger.getLogger(MessageController.class);

	@Resource
	private MessageService messageService;

	@Resource
	private LogService logService;
	
	/**
	 * 获取消息通知列表
	 * @param request
	 * @param response
	 * @param weixinId
	 * @param houseId
	 * @param title
	 * @param currentPage
	 * @param pageSize
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getMessageList")
	public void getMessageList(HttpServletRequest request,
			HttpServletResponse response, String weixinId,String houseId,String title,
			String currentPage,String pageSize) {
		ResultVo resultVo = new ResultVo();
		try {
			int total = (int)messageService.getMessageListCount(weixinId,houseId,title,null);
			PageVo<Message> pageVo = new PageVo<Message>(currentPage,total,pageSize);
			List<Message> list = messageService.getMessageList(weixinId,houseId,title,pageVo.getpageIndex(),pageVo.getpageSize(),null);
			pageVo.setData(list);
			resultVo.setSuccess(true);
			resultVo.setData(pageVo);
			log.info("消息通知 查看成功!");
		} catch (Exception e) {
			resultVo.setSuccess(false);
			resultVo.setMessage("消息通知  查看失败");
			log.error("消息通知 查看失败!", e);
		}
		CommonUtil.PrintWriterResultVoWithJSON(response, resultVo);
	}
	
	/**
	 * 查看消息通知详情
	 * 
	 * @param request
	 * @param response
	 * @param id
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/getMessageById")
	public void getMessageById(HttpServletRequest request,
			HttpServletResponse response, String id) {
		ResultVo resultVo = new ResultVo();
		try {
			Message message = messageService.getMessageById(id);
			resultVo.setSuccess(true);
			resultVo.setData(message);
			log.info("消息通知 查看成功!");
		} catch (Exception e) {
			resultVo.setSuccess(false);
			resultVo.setMessage("消息通知  查看失败");
			log.error("消息通知 查看失败!", e);
		}
		CommonUtil.PrintWriterResultVoWithJSON(response, resultVo);
	}
	
}
